import { useState,useEffect } from 'react';
import './index.css';

const Header = ()=>{
      const [arr, setArr] = useState([0]);

  useEffect(() => {
    console.log(arr);
  }, [arr]);

  const handleClick = () => {
    Promise.resolve().then(() => {
      setArr([...arr, 1]); // 此时赋值前 arr 为：[0]
    })
      .then(() => {
        setArr([...arr, 2]); // 此时赋值前 arr 为旧状态仍然为：[0]
      });
  };

  return (
    <>
      <button onClick={handleClick}>change</button>
      <hr></hr>
      <a target='_blank' href={'asad'} rel="noreferrer">测试下是否会渲染</a>
    </>
  );
};

export default Header;